'use strict';
const { timeFormater } = require('../utils/tools');
module.exports = app => {
  const { BIGINT, DATE, STRING, INTEGER, CHAR } = app.Sequelize;
  return app.model.define('File', {
    id: {
      type: BIGINT,
      allowNull: false,
      primaryKey: true,
      autoIncrement: true,
      field: 'id',
    },
    batchNo: {
      type: STRING(50),
      allowNull: true,
      field: 'batch_no',
    },
    fileName: {
      type: STRING(128),
      allowNull: true,
      field: 'file_name',
    },
    fileUrl: {
      type: STRING(255),
      allowNull: true,
      field: 'file_url',
    },
    fileDesc: {
      type: STRING(255),
      allowNull: true,
      field: 'file_desc',
    },
    message: {
      type: STRING(255),
      allowNull: true,
      field: 'message',
    },
    relatedUrl: {
      type: STRING(255),
      allowNull: true,
      field: 'related_url',
    },
    status: {
      type: INTEGER(2),
      allowNull: true,
      field: 'status',
    },
    createId: {
      type: STRING(20),
      allowNull: true,
      field: 'create_id',
    },
    paymentTime: {
      type: DATE,
      allowNull: true,
      field: 'payment_time',
      get() {
        return timeFormater(this.getDataValue('paymentTime'));
      },
    },
    createdTime: {
      type: DATE,
      allowNull: true,
      field: 'created_time',
      get() {
        return timeFormater(this.getDataValue('createdTime'));
      },
    },
    updatedTime: {
      type: DATE,
      allowNull: true,
      field: 'updated_time',
      get() {
        return timeFormater(this.getDataValue('updatedTime'));
      },
    },
    hash: {
      type: CHAR(64),
      allowNull: true,
      field: 'hash',
    },
  }, {
    tableName: 'file',
    timestamps: false,
  });
};
